package com.gaohe.official.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gaohe.common.log.annotation.Log;
import com.gaohe.common.log.enums.BusinessType;
import com.gaohe.common.security.annotation.RequiresPermissions;
import com.gaohe.official.domain.FmCommunityTopic;
import com.gaohe.official.service.IFmCommunityTopicService;
import com.gaohe.common.core.web.controller.BaseController;
import com.gaohe.common.core.web.domain.AjaxResult;
import com.gaohe.common.core.utils.poi.ExcelUtil;
import com.gaohe.common.core.web.page.TableDataInfo;

/**
 * 圈子栏目Controller
 *
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/communityTopic")
public class FmCommunityTopicController extends BaseController
{
    @Autowired
    private IFmCommunityTopicService fmCommunityTopicService;

    /**
     * 查询圈子栏目列表
     */
    @RequiresPermissions("official:topic:list")
    @GetMapping("/list")
    public TableDataInfo list(FmCommunityTopic fmCommunityTopic)
    {
        startPage();
        List<FmCommunityTopic> list = fmCommunityTopicService.selectFmCommunityTopicList(fmCommunityTopic);
        return getDataTable(list);
    }

    /**
     * 导出圈子栏目列表
     */
    @RequiresPermissions("official:topic:export")
    @Log(title = "圈子栏目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmCommunityTopic fmCommunityTopic)
    {
        List<FmCommunityTopic> list = fmCommunityTopicService.selectFmCommunityTopicList(fmCommunityTopic);
        ExcelUtil<FmCommunityTopic> util = new ExcelUtil<FmCommunityTopic>(FmCommunityTopic.class);
        util.exportExcel(response, list, "圈子栏目数据");
    }

    /**
     * 获取圈子栏目详细信息
     */
    @RequiresPermissions("official:topic:query")
    @GetMapping(value = "/{communityTopicId}")
    public AjaxResult getInfo(@PathVariable("communityTopicId") Long communityTopicId)
    {
        return success(fmCommunityTopicService.selectFmCommunityTopicByCommunityTopicId(communityTopicId));
    }

    /**
     * 新增圈子栏目
     */
    @RequiresPermissions("official:topic:add")
    @Log(title = "圈子栏目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmCommunityTopic fmCommunityTopic)
    {
        return toAjax(fmCommunityTopicService.insertFmCommunityTopic(fmCommunityTopic));
    }

    /**
     * 修改圈子栏目
     */
    @RequiresPermissions("official:topic:edit")
    @Log(title = "圈子栏目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmCommunityTopic fmCommunityTopic)
    {
        return toAjax(fmCommunityTopicService.updateFmCommunityTopic(fmCommunityTopic));
    }

    /**
     * 删除圈子栏目
     */
    @RequiresPermissions("official:topic:remove")
    @Log(title = "圈子栏目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{communityTopicIds}")
    public AjaxResult remove(@PathVariable Long[] communityTopicIds)
    {
        return toAjax(fmCommunityTopicService.deleteFmCommunityTopicByCommunityTopicIds(communityTopicIds));
    }
}
